package;

/* Our framework */
import org.flixel.FlxG;
import org.flixel.FlxState;
import org.flixel.FlxText;

/* 
 * Menu state, is the first screen that appears, 
 * it's holds the options, and the trigger to start
 * the adventure
 */
class StateMenu extends FlxState {
    /*
     * Instantiate our first menu
     */
    public function new() {
        super();
    }

    /*
     * Here we override the process to creation with our own ideas 
     */
    override public function create() {
        /* Main title: Last Space Defender */
        var _game_name:FlxText = new FlxText(0, 50, FlxG.width, "Last Space Defender");
        _game_name.setFormat(null, 42, 0xFFE01800, "center", 0xFFFC3C00);
        add(_game_name);

        /* This is the high score, we must connect him in a data base */
        //var _max_record:FlxText = new FlxText(0, 100, FlxG.width, "HIGH SCORE: " + Game._high_score);
        //_max_record.setFormat(null, 18, 0xFFFFFFFF, "center", 0xFF999392);
        //add(_max_record);				

        /* Instructions how to play */
        var _inst:FlxText = new FlxText(0, 250, FlxG.width,
                            "X Blast, C Shot, Direction Keys To Move");
        _inst.setFormat(null, 18, 0xFFFFFFFF, "center", 0xFF999999);
        add(_inst);
        
        /* Show how to start the game */
        var _keys:FlxText = new FlxText(0, 280, FlxG.width, "Press X, C To Start");
        _keys.setFormat(null, 18, 0xFFD9D0CF, "center", 0xFF999392);
        add(_keys);
        
        /* Setup and show the top panel */
        FlxG.panel.setup("", 0, "Last Space Defenfer", "", "");
        FlxG.mouse.show();
        FlxG.panel.show();

        /* Calls the parent */
        super.create();
    }

    /*
     * Callback to start after fade
     */
    private function onStart():Void {
        FlxG.setState(new StatePlay());
    }

    /*
     * Override the loop, this method is update every time
     * and here we put our control, what we waiting for to 
     * activate a lot of actions
     */
    override public function update() {
        
        /* If pressed C or X a little fadeout, and the new state is called */
        if(FlxG.keys.justPressed("C") || FlxG.keys.justPressed("X")) {
            FlxG.fade.start(0xFF000000, 1, onStart);
        }
        
        /* Calls the parent */
        super.update();
    }
}
